﻿using System.ComponentModel;
using Moq;
using NUnit.Framework;

namespace Google.Analytics.WebTests
{
    [TestFixture]
    public abstract class ConverterTestBase<T, TResult> where T : new()
    {
        protected T Converter;

        [SetUp]
        public void SetUp()
        {
            Converter = new T();
        }

        protected ITypeDescriptorContext GetTypeContext()
        {
            var typeDescriptorMock = new Mock<ITypeDescriptorContext>();
            return typeDescriptorMock.Object;
        }

        protected virtual void VerifyConverFromResult(object result, TResult[] array)
        {
            Assert.That(result is TResult[], "Returned object was not array");
            var resultArray = (TResult[])result;
            Assert.AreEqual(array.Length, resultArray.Length, "Invalid size of the array");
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(array[i], resultArray[i], "Invalid array item");
            }
        }

        protected virtual void VerifyCovnertToResult(object result, string expected)
        {
            Assert.That(result is string, "Returned object was not string");
            var resultString = (string)result;
            Assert.AreEqual(expected, resultString, "Invalid result");
        }
    }
}
